package org.example.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.dao.branddao;
import org.example.domain.brand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class brandserviceimpl extends ServiceImpl<branddao, brand> implements brandservoce {
@Autowired
    private branddao branddao;
    @Override
    public IPage getPage(int pageNum, int pageSize) {
        IPage page = new Page(pageNum, pageSize);

        branddao.selectPage(page,null);
        return page;
    }

    @Override
    public IPage getPage(int pageNum, int pageSize, brand brand1) {
        IPage page = new Page(pageNum, pageSize);
        LambdaQueryWrapper<brand> wrapper = new LambdaQueryWrapper<>();

        //brand::getBrandname对应你定义类的属性名，而类与数据库表绑定在一起，从而映射到数据库表
        //brand1.getBrandname()就是用来获取前端传过来的数据，?type=小说&name=三体&description=科幻 是查询参数，
        // 会被后端自动绑定到 Book 对象的对应属性上（只要属性名与参数名一致）。
        //分页条件查询，非常重要
        wrapper.like(brand1.getBrandname()!=null,brand::getBrandname,brand1.getBrandname());
         branddao.selectPage(page,wrapper);
        return page;
    }
}
